package cn.didi.feidi.javabackend.server.waterdeliver.repository;


import cn.didi.feidi.javabackend.mysql.jpa.waterDeliver.WaterDeliver;
import cn.didi.feidi.javabackend.server.waterdeliver.constant.address.MysqlJpaHttpAddress;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

import static cn.didi.feidi.javabackend.server.waterdeliver.utils.UrlUtil.getServerURL;

/**
 * Created by lindanpeng on 2017/7/16.
 */
@Repository
//@ComponentScan(basePackages = {"cn.didi.feidi.javabackend.server.waterDeliver.constant"})
public class WaterDeliverRep extends BaseRep<WaterDeliver> {

  /*  //   @Autowired
    RestTemplate restTemplate = new RestTemplate();

    public WaterDeliver getByWaterDeliverId(String waterDeliverId){
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("waterDeliverId", waterDeliverId);
        String path = "waterDeliver/getById";
        WaterDeliver waterDeliver = restTemplate.getForObject(getServerURL(MysqlJpaHttpAddress.mysqlJpaHost, MysqlJpaHttpAddress.mysqlJpaPort, path, params),WaterDeliver.class);
        return waterDeliver;
    }
    public void add(WaterDeliver waterDeliver){
        String path = "waterDeliver/add";
       // restTemplate.postForObject(getServerURL(RedisHttpAddress.redisHost,  RedisHttpAddress.redisPort, path, null), waterDeliver, String.class);
        restTemplate.postForObject(getServerURL(MysqlJpaHttpAddress.mysqlJpaHost, MysqlJpaHttpAddress.mysqlJpaPort, path, null), waterDeliver, String.class);
    }

    public void update(WaterDeliver waterDeliver){
        String path = Thread.currentThread().getStackTrace()[1].getMethodName();
        restTemplate.postForObject(getServerURL(RedisHttpAddress.redisHost,  RedisHttpAddress.redisPort, path, null), waterDeliver, String.class);
        restTemplate.postForObject(getServerURL(MysqlJpaHttpAddress.mysqlJpaHost, MysqlJpaHttpAddress.mysqlJpaPort, path, null), waterDeliver, String.class);
    }

    public void deleteById(String waterDeliverId){
        Map<String, Object> params = new HashMap<>();
        params.put("waterDeliverId", waterDeliverId);
        String path ="waterDeliver/deleteById";
        restTemplate.delete(getServerURL(RedisHttpAddress.redisHost,  RedisHttpAddress.redisPort, path, params));
        restTemplate.delete(getServerURL(MysqlJpaHttpAddress.mysqlJpaHost, MysqlJpaHttpAddress.mysqlJpaPort, path, params));
    }

    public WaterDeliver getByPhoneNumber(String phoneNumber) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("phoneNumber", phoneNumber);
        String path = "waterDeliver/getByPhoneNumber";
        WaterDeliver  waterDeliver = restTemplate.getForObject(getServerURL(MysqlJpaHttpAddress.mysqlJpaHost, MysqlJpaHttpAddress.mysqlJpaPort, path, params),WaterDeliver.class);
        return waterDeliver;
    }
*/
  public WaterDeliver getByPhoneNumber(String phoneNumber) {
      String methodName=Thread.currentThread().getStackTrace()[1].getMethodName();
      String path=pathPrefix+"/"+methodName;
      Map<String, Object> params = new HashMap<String, Object>();
      params.put("phoneNumber", phoneNumber);
      WaterDeliver  waterDeliver = restTemplate.getForObject(getServerURL(MysqlJpaHttpAddress.mysqlJpaHost, MysqlJpaHttpAddress.mysqlJpaPort, path, params),WaterDeliver.class);
      return waterDeliver;
  }
}

